package com.nhim.cms.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

/**
 * CustomWidget entity. @author Huy Lieu Ta
 */
@Entity
@Table(name = "nhim_custom_widget", catalog = "nhim_cms")
public class CustomWidget implements java.io.Serializable {

	
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;
	private String description;
	private String className;
	private Integer version;
	private Set<CustomWidgetInstance> customWidgetInstances = new HashSet<CustomWidgetInstance>(
			0);
	
	// Constructors

	/** default constructor */
	public CustomWidget() {
	}

	/** minimal constructor */
	public CustomWidget(String name,
			String className) {
		this.name = name;
		this.className = className;
	}

	/** full constructor */
	public CustomWidget(String name,String className , String description, Set<CustomWidgetInstance> customWidgetInstances, Integer version) {
		this.name = name;
		this.className  = className;
		this.description = description;
		this.customWidgetInstances = customWidgetInstances;
		this.version = version;
		
	}

	
	
	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name = "name", nullable = false, length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "description", length = 200)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	
	@Column(name = "className",nullable = false, length = 500)
	public String getClassName() {
		return this.className;
	}

	public void setClassName(String className) {
		this.className = className;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "customWidget")
	public Set<CustomWidgetInstance> getCustomWidgetInstances() {		
		return this.customWidgetInstances;
	}

	public void setCustomWidgetInstances(Set<CustomWidgetInstance> customWidgetInstances) {
		this.customWidgetInstances = customWidgetInstances;
	}
	
	@Version
	@Column(name = "version")
	public Integer getVersion() {
		return this.version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

}
